<template>
	<w-layout showNavbar navTitle="我的收藏" :navTitleColor="publicStyles['--color-t1']" background="url('/static/image/bk.png') no-repeat"
		navBackgroundColor="transparent" :scrollTop="page.scrollTop" :navScrollColor="publicStyles['--color-bk']">
		<template #default>
			<view class="container">
				<view class="fr-ac-jsb">
					<view class="flex-1 mr-40">
						<up-tabs
							@change="tabChange"
							:list="tabs.list" 
							:current="tabs.current"
							lineWidth="14"
							lineHeight="14"
							:lineColor="`url('/static/icon/public/top-fill.png') 100% 100%`"
							:activeStyle="{
								color: publicStyles['--color'],
								fontWeight: 'bold',
								transform: 'scale(1.2)'
							}"
							:scrollable="true"
							itemStyle="height: 60px;"
							:inactiveStyle="{
								'font-size': '32rpx',
							}"
						>
						</up-tabs>
					</view>
				</view>
				
				<view class="gap-30 mt-40" style="display: grid;grid-template-columns: repeat(2,1fr);">
					<view @click="gopage(item)" class="public-card-8 fc px-30 py-30" style="min-height: 360rpx;" v-for="(item,index) in state.list" :key="index">
						<image style="width: 100%;height: 250rpx;" :src="item.imgurl" mode="widthFix"></image>
						<view class="mt-30 fs-24 ellipsis-2">
							{{item.goods_title}}
						</view>
						<view class="fr-ac-jsb mt-20">
							<!-- <view class="op-50 fs-24">
								3453染参加
							</view> -->
							<view class="color fs-24">
								¥{{item.goods_price}}
							</view>
						</view>
					</view>
				</view>
				<no-more :show="state.list.length == 0"></no-more>
				
			</view>
		</template>
	</w-layout>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		computed,
		nextTick
	} from 'vue'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad, onPageScroll,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		useAppStore
	} from '@/store/app'
	import {
		useColorStore
	} from '@/store/color'
	import {
		listCollect
	} from '@/utils/request/api';
	import {
		useUserStore
	} from '@/store/user'
	const userStore = useUserStore()
	const appStore = useAppStore()
	const colorStore = useColorStore()
	const {
		publicStyles
	} = storeToRefs(colorStore)
	onLoad(async(options) => {
		get_listCollect()
	})
	onMounted(() => {
		appStore.loadingHandler(false)
	})
	onPageScroll((e)=>{
		page.scrollTop = e.scrollTop
	})
	onReachBottom(()=>{
		if(state.last_limit == state.limit){
			state.page++
			get_listCollect()
		}
	})
	const page = reactive({
		scrollTop:0
	})
	
	const state = reactive({
		list:[],
		page:1,
		limit:15,
		last_limit:15,
	})
	function initData(){
		state.list = []
		state.page = 1
		state.last_limit = 15
	}
	
	const tabs = reactive({
		current:0,
		list:[
			{
				id:0,
				name:'全部',
			},
			{
				id:2,
				name:'无限赏',
			},
			{
				id:1,
				name:'一番赏',
			},
			{
				id:5,
				name:'精气赏',
			},
			{
				id:3,
				name:'擂台赏',
			},
			{
				id:8,
				name:'领主赏',
			}
		]
	})
	function tabChange(e){
		console.log(tabs.current)
		tabs.current = e.index
		initData()
		get_listCollect()
	}
	
	
	async function get_listCollect(){
		const res = await listCollect({
			page: state.page,
			type: tabs.list[tabs.current].id
		})
		state.last_limit = res.data.length
		state.list = state.list.concat(res.data)
	}
	
	function gopage(item){
		let url = ''
		switch (item.type){
			case 2:
				url = `/pages/wuxian_shang/index?id=${item.goods_id}`
				break;
			case 1:
				url = `/pages/yifan_shang/index?id=${item.goods_id}&num=${item.num}`
				break;
			case 5:
				url = `/pages/yuanqi_shang/index?id=${item.goods_id}&num=${item.num}`
				break;
			case 8:
				url = `/pages/wuxian_shang/index?id=${item.goods_id}`
				break;
			case 3:
				url = `/pages/leitai_shang/index?id=${item.goods_id}`
				break;
			default:
				break;
		}
		uni.navigateTo({
			url
		})
	}
</script>

<style lang="scss">
	.shadow {
		box-shadow: 2rpx 2rpx 12rpx var(--shadow);
	}
	.color{
		color: var(--color);
	}

	.container {
		width: 100%;
		min-height: 100%;
		position: relative;
		overflow: hidden;
		box-sizing: border-box;
		padding: 0 40rpx;
		min-height: 100vh;
	}
	
	.login-btn {
		color: white !important;
		background: var(--color) !important;
		border-radius: 12rpx !important;
	}
	
	::v-deep .u-number-box__minus,.u-number-box__plus{
		background-color: transparent !important;
	}
</style>